/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author karennyq
 */
public class Csv {

    String fileName = "Attempts.csv";

    public boolean generateCsvFile(ArrayList<ArrayList> contents) {
        try {
            FileWriter writer = new FileWriter(fileName);

            for (int i = 0; i < contents.size(); i++) {
                for (int j = 0; j < contents.get(i).size(); j++) {
                    ArrayList rowContent = contents.get(i);
                    writer.append("\"");
                    writer.append(rowContent.get(j).toString());
                    writer.append("\"");

                    if (j < contents.get(i).size() - 1) {
                        writer.append(',');
                    } else {
                        writer.append('\n');
                    }
                }
            }

            writer.flush();
            writer.close();
            return true;

        } catch (IOException e) {
            return false;
        }
    }
}
